﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NewRen.Models.ViewModel
{
    /// <summary>
    /// 收藏
    /// </summary>
    public class vCollect
    {
        public int ID { get; set; }

        public int TID { get; set; }

        public int UserID { set; get; }

        public string UserName { set; get; }


        public string TName { set; get; }

        public string URL { set; get; }

        public int CollectTypeAsInt { set; get; }

        public DateTime Time { set; get; }

        public vCollect() { }

        public vCollect(Collect model)
        {
            this.ID = model.ID;
            this.TID = model.TID;
            this.CollectTypeAsInt = model.CollectTypeAsInt;
            this.UserID = model.UserID;
            this.UserName = model.User.UserName;
            this.Time = model.Time;
            using (DB db = new DB())
            {
                if (model.CollectType == CollectType.User)
                {
                    var user = db.Users.Find(model.TID);
                    this.URL = "/User/PersonalShow/" + user.ID;
                    this.TName = user.UserName;
                }
                if (model.CollectType == CollectType.UserGroup)
                {
                    var group = db.UserGroups.Find(model.TID);
                    this.URL = "/UserGroup/UserGroupShow/" + model.ID;
                    this.TName = group.GroupName;
                }
                if (model.CollectType == CollectType.Forum)
                {
                    var  forum = db.Plates.Find(model.TID);
                    this.URL = "/Bbs/ShowForumPicture/" + model.ID;
                    this.TName = forum.Title;
                }
            }
        }


    }
}
